home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue50 / IPC / Anonymous Pipes / Delphi / ChildMainFormUnit.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-08-28  |  1023 b   |  51 lines

  1. unit ChildMainFormUnit;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Edit1: TEdit;
  12.     Button1: TButton;
  13.     procedure FormCreate(Sender: TObject);
  14.     procedure FormDestroy(Sender: TObject);
  15.     procedure Button1Click(Sender: TObject);
  16.   private
  17.     PipeWrite: THandle;
  18.   end;
  19.  
  20. {$ifdef Ver90}
  21.   //This exception class did not exist in Delphi 2
  22.   EWin32Error = class(Exception);
  23. {$endif}
  24.  
  25. var
  26.   Form1: TForm1;
  27.  
  28. implementation
  29.  
  30. {$R *.DFM}
  31.  
  32. procedure TForm1.FormCreate(Sender: TObject);
  33. begin
  34.   PipeWrite := GetStdHandle(Std_Output_Handle)
  35. end;
  36.  
  37. procedure TForm1.FormDestroy(Sender: TObject);
  38. begin
  39.   FileClose(PipeWrite);
  40. end;
  41.  
  42. procedure TForm1.Button1Click(Sender: TObject);
  43. var
  44.   Msg: String;
  45. begin
  46.   Msg := Edit1.Text + #13#10;
  47.   if FileWrite(PipeWrite, Msg[1], Length(Msg)) = Integer(HFile_Error) then
  48.     raise EWin32Error.Create('Cannot write to anonymous pipe');
  49. end;
  50.  
  51. end.